module.exports = {
  devServer: {
    proxy: {
      '/api': {
        target: 'http://localhost:8888',
        secure: false,
        bypass: function(req, res) {
          if (req.headers.accept.indexOf('html') !== -1) {
            console.log('Skipping proxy for browser request.')
            return '/index.html'
          } else {
            console.log('请求地址', req.path)
            const name = req.path
              .split('/api/')[1]
              .split('/')
              .join('_')
            const mock = require(`./src/mock/${name}`)
            const result = mock(req.method)

            delete require.cache[require.resolve(`./src/mock/${name}`)]
            return res.send(result)
          }
        }
      },
      '/aip': {
        target: 'https://aip.baidubce.com/',
        changeOrigin: true,
        pathRewrite: {
          '^/aip/': '/' // remove base path
        }
      }
    }
  }
}
